package org.hackystat.ambientdevice.device.bunny;

import java.util.logging.Logger;
import org.hackystat.ambientdevice.ConfigurationException;
import org.hackystat.ambientdevice.device.AmbientAction;
import org.hackystat.ambientdevice.device.bunny.Nabaztag.EarPosition;

/**
 * A class to move the left ear.
 * 
 * @author Sonny Gomez
 */
public class ChangeLeftEarPosition implements AmbientAction {
  /** the Nabaztag that will change its ear positions. */
  private Nabaztag nabaztag;
  /** the left Ear Position for the Nabaztag bunny. */
  private EarPosition leftPos;
  /** Logger. **/
  private Logger logger = Logger.getLogger("org.hackystat.ambientdevice");

  /**
   * Constructor for ChangeLeftEarPosition.
   * @param nabaztag containing the Nabaztag bunny.
   * @param leftPos containing the position of the left ear.
   * @throws ConfigurationException if Unsupported value is given.
   */
  public ChangeLeftEarPosition(Nabaztag nabaztag, String leftPos) throws ConfigurationException {
    this.nabaztag = nabaztag;
    this.leftPos = EarPosition.getEnumValue(leftPos);
    if (this.leftPos == EarPosition.Unsupported) {
      throw new ConfigurationException("Ear Position" + leftPos + " not supported by Nabaztag.");
    }
  }

  /**
   * Change the bunny's left ear position according to data given.
   */
  public void act() {
    logger.info("Change Nabaztag's Left Ear Position to " + leftPos);
    nabaztag.setLeftPos(leftPos);
    nabaztag.updateLeftEarState();
  }

  /**
   * @return the Nabaztag bunny.
   */
  public Nabaztag getNabaztag() {
    return this.nabaztag;
  }

  /**
   * @return the left ear position.
   */
  public EarPosition getLeftEarPosition() {
    return this.leftPos;
  }
}
